<?php
session_start();
if(!isset($_SESSION['uid']))
 	{?>
		<script type="text/javascript">
			window.location="error.php";
		</script>
	<?php
 	}else
 		{
			include_once 'dataBaseConnectivityFile.php';
			$Deleteitem_id=$_REQUEST["stock_id"];
			
			$sql_get2=mysql_query("SELECT * FROM stock where STOCK_ID  = ".$Deleteitem_id."  ");
			while ($db_result2=mysql_fetch_assoc($sql_get2))
				{
			      $IMAGE_PATH=$db_result2["IMAGE_PATH"];
				}
				
				$files1 = $IMAGE_PATH;
					if(is_file($files1))
						{
				    		unlink($files1);
						}
 			
			$sql_get=mysql_query("SELECT * FROM vehicle_image where STOCK_ID  = ".$Deleteitem_id."  ");
			while ($db_result3=mysql_fetch_assoc($sql_get))
				{
			      $PATH=$db_result3["PATH"];
				  $files2 = $PATH;
					if(is_file($files2))
						{
				    		unlink($files2);
						}
				}						
			mysql_query("DELETE from stock where STOCK_ID=".$Deleteitem_id." ");
			mysql_query("DELETE from additional_features where STOCK_ID=".$Deleteitem_id." ");
			mysql_query("DELETE from exterior where STOCK_ID=".$Deleteitem_id." ");
			mysql_query("DELETE from fuel_specification where STOCK_ID=".$Deleteitem_id." ");
			mysql_query("DELETE from mechanics where STOCK_ID=".$Deleteitem_id." ");
			mysql_query("DELETE from overview where STOCK_ID=".$Deleteitem_id." ");
			mysql_query("DELETE from safety where STOCK_ID=".$Deleteitem_id." ");
			mysql_query("DELETE from stock where STOCK_ID=".$Deleteitem_id." ");
			mysql_query("DELETE from vehicle_condition where STOCK_ID=".$Deleteitem_id." ");
			mysql_query("DELETE from vehicle_image where STOCK_ID=".$Deleteitem_id." ");								
	 	}
 ?>
			    <script type="text/javascript">
			        alert(<?php echo $Deleteitem_id?>+" Stock Item Deleted");
			        window.location="viewCar.php"
			    </script>